//
//  UIBarButtonItem+Extension.swift
//  CopyWB
//
//  Created by 翁胜琼 on 2017/5/12.
//  Copyright © 2017年 iimac. All rights reserved.
//

import UIKit

extension UIBarButtonItem{

    //创建UIBarButtonItem
    
    //设置按钮，如果isBackBtn  == true 则是导航栏上的返回按钮需要加上箭头
    convenience init?(title : String , fontSize : CGFloat , target : AnyObject , action : Selector , isBackBtn : Bool = false){
        let btn : UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: .orange)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBackBtn {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named:imageName), for: .normal)
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        self.init(customView: btn)
    }
}
